<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import { FormInstance } from '@arco-design/web-vue'
import useOptions from '@/hooks/useOptions'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  categoryId: [] as any,
  ids: props.id,
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      query.categoryId = JSON.stringify(detail.categoryId)
      post(
        { url: '/server-shop/admin/goods/update/category/batch', data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          if (code == 200) {
            emit('update:show', false)
            emit('confirm')
          }
          done(code == 200)
        },
        () => done(false)
      )
    } else done(false)
  })
}
/**平台商品分类 */
const { options: platformCategory } = useOptions({
  api: '/server-shop/admin/goods/category/tree',
})
</script>
<template>
  <CDrawer v-model:visible="props.show" @before-ok="submit" :mask-closable="false" width="500px" title="批量修改分类" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item field="categoryId" label="平台商品分类" :rules="[{ required: true, message: '请选择分类' }]" :validate-trigger="['change', 'blur']">
          <a-cascader v-model="detail.categoryId" multiple allow-clear :options="platformCategory" path-mode placeholder="请选择分类" :field-names="{ label: 'title', value: 'id' }" />
        </a-form-item>
      </a-form>
    </div>
  </CDrawer>
</template>
<style lang="less" scoped></style>
